; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -constraint-elimination -S %s | FileCheck %s

define void @pointer.to.array.test.ult.true.due.to.first.dimension([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.ult.true.due.to.first.dimension(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 9, i64 3
; CHECK-NEXT:    [[C_1:%.*]] = icmp ule i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 5, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp ult i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 9, i64 3
  %c.1 = icmp ule i8* %add.ptr.i, %high
  br i1 %c.1, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 5, i64 0
  %c.0 = icmp ult i8* %start.0, %high
  call void @use(i1 %c.0)

  ret void

if.end:                                           ; preds = %entry
  ret void
}

define void @pointer.to.array.test.ult.unknown.due.to.first.dimension([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.ult.unknown.due.to.first.dimension(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 5, i64 3
; CHECK-NEXT:    [[C_1:%.*]] = icmp ule i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 10, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp ult i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 5, i64 3
  %c.1 = icmp ule i8* %add.ptr.i, %high
  br i1 %c.1, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 10, i64 0
  %c.0 = icmp ult i8* %start.0, %high
  call void @use(i1 %c.0)

  ret void

if.end:                                           ; preds = %entry
  ret void
}

define void @pointer.to.array.test.ult.true.due.to.second.dimension([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.ult.true.due.to.second.dimension(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 5, i64 1
; CHECK-NEXT:    [[C_1:%.*]] = icmp ule i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 5, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp ult i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 5, i64 1
  %c.1 = icmp ule i8* %add.ptr.i, %high
  br i1 %c.1, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 5, i64 0
  %c.0 = icmp ult i8* %start.0, %high
  call void @use(i1 %c.0)

  ret void

if.end:                                           ; preds = %entry
  ret void
}

define void @pointer.to.array.test.ult.unknown.to.second.dimension([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.ult.unknown.to.second.dimension(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 5, i64 0
; CHECK-NEXT:    [[C_1:%.*]] = icmp ule i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 5, i64 1
; CHECK-NEXT:    [[C_0:%.*]] = icmp ult i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 5, i64 0
  %c.1 = icmp ule i8* %add.ptr.i, %high
  br i1 %c.1, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 5, i64 1
  %c.0 = icmp ult i8* %start.0, %high
  call void @use(i1 %c.0)

  ret void

if.end:                                           ; preds = %entry
  ret void
}

define void @pointer.to.array.test.not.uge.ult([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.not.uge.ult(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 1, i64 3
; CHECK-NEXT:    [[C_1:%.*]] = icmp uge i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 10, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp ult i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 1, i64 3
  %c.1 = icmp uge i8* %add.ptr.i, %high
  br i1 %c.1, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  ret void

if.end:                                           ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 10, i64 0
  %c.0 = icmp ult i8* %start.0, %high
  call void @use(i1 %c.0)
  ret void
}

define void @pointer.to.array.test.not.uge.ule([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.not.uge.ule(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 1, i64 3
; CHECK-NEXT:    [[C:%.*]] = icmp uge i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 10, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp ule i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    [[START_1:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 2, i64 1
; CHECK-NEXT:    [[C_1:%.*]] = icmp ule i8* [[START_1]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_1]])
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 1, i64 3
  %c = icmp uge i8* %add.ptr.i, %high
  br i1 %c, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  ret void

if.end:                                           ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 10, i64 0
  %c.0 = icmp ule i8* %start.0, %high
  call void @use(i1 %c.0)
  %start.1 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 2, i64 1
  %c.1 = icmp ule i8* %start.1, %high
  call void @use(i1 %c.1)
  ret void
}

define void @pointer.to.array.test.not.uge.ugt([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.not.uge.ugt(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 1, i64 3
; CHECK-NEXT:    [[C:%.*]] = icmp uge i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 3, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp ugt i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    [[START_1:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 3, i64 1
; CHECK-NEXT:    [[C_1:%.*]] = icmp ugt i8* [[START_1]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_1]])
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 1, i64 3
  %c = icmp uge i8* %add.ptr.i, %high
  br i1 %c, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  ret void

if.end:                                           ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 3, i64 0
  %c.0 = icmp ugt i8* %start.0, %high
  call void @use(i1 %c.0)

  %start.1 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 3, i64 1
  %c.1 = icmp ugt i8* %start.1, %high
  call void @use(i1 %c.1)
  ret void
}

define void @pointer.to.array.test.not.uge.uge([10 x i8]* %start, i8* %high) {
; CHECK-LABEL: @pointer.to.array.test.not.uge.uge(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[ADD_PTR_I:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START:%.*]], i64 1, i64 3
; CHECK-NEXT:    [[C_1:%.*]] = icmp uge i8* [[ADD_PTR_I]], [[HIGH:%.*]]
; CHECK-NEXT:    br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    ret void
; CHECK:       if.end:
; CHECK-NEXT:    [[START_0:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[START]], i64 3, i64 0
; CHECK-NEXT:    [[C_0:%.*]] = icmp uge i8* [[START_0]], [[HIGH]]
; CHECK-NEXT:    call void @use(i1 [[C_0]])
; CHECK-NEXT:    ret void
;
entry:
  %add.ptr.i = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 1, i64 3
  %c.1 = icmp uge i8* %add.ptr.i, %high
  br i1 %c.1, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  ret void

if.end:                                           ; preds = %entry
  %start.0 = getelementptr inbounds [10 x i8], [10 x i8]* %start, i64 3, i64 0
  %c.0 = icmp uge i8* %start.0, %high
  call void @use(i1 %c.0)

  ret void
}

declare void @use(i1)
